var stepPortletArr:Array=["UsrInfoView", "TaskPaper", "RecordingGuide", "RecordingSpace", "PostProduction", "Report"];
var _home="HomePage";
var _recorder="ReadingRecorder";
var _player="Player";

var recorderGuidePortletArr:Array=new Array();
var recorderStep0Arr:Array=["UsrInfoView_signin", "UsrInfoView_tutorial"];
recorderGuidePortletArr.push(recorderStep0Arr);
var recorderStep1Arr:Array=["TaskPaper_upload", "TaskPaper_book"];
recorderGuidePortletArr.push(recorderStep1Arr);
var recorderStep2Arr:Array=["RecordingGuide_mic", "RecordingGuide_format", "RecordingGuide_block", "RecordingGuide_ready"];
recorderGuidePortletArr.push(recorderStep2Arr);
var recorderStep3Arr:Array=["RecordingSpace_start", "RecordingSpace_stop", "RecordingSpace_finish"];
recorderGuidePortletArr.push(recorderStep3Arr);
var recorderStep4Arr:Array=["PostProduction_preview", "PostProduction_convert", "PostProduction_publish"];
recorderGuidePortletArr.push(recorderStep4Arr);
var recorderStep5Arr:Array=["Report_done"];
recorderGuidePortletArr.push(recorderStep5Arr);

var currentGuideInstance;

function enterCommunity(param, data, slot)
{
	mlf.mcmanager.SMCManager.popInstance(slot);

	mlf.gatekeeper.native.Caller.MLoader("app/Community.xml");
	Packages.system.DeepLinking.setDeepLinkingValue("Community");
}

function enterRecorder(param, data, slot)
{
	mlf.mcmanager.SMCManager.popInstance(slot);

	mlf.gatekeeper.native.Caller.MLoader("app/ReadingRecorder.xml");
	Packages.system.DeepLinking.setDeepLinkingValue("ReadingRecorder");
}

function enterPlayer(param, data, slot)
{
	mlf.mcmanager.SMCManager.popInstance(slot);

	mlf.gatekeeper.native.Caller.MLoader("app/Player.xml");
	Packages.system.DeepLinking.setDeepLinkingValue("Player");
}

function enterSurveyPaper(param, data, slot)
{
	mlf.mcmanager.SMCManager.popInstance(slot);

	mlf.gatekeeper.native.Caller.MLoader("app/SurveyPaper.xml");
}

function container2Scene(container, slot, target)
{
	mlf.mcmanager.SMCManager.popInstance(container);
	mlf.mcmanager.SMCManager.popInstance(slot);

	mlf.gatekeeper.native.Caller.MLoader("app/"+target+".xml");
}

function enterHomePage(param, data, slot)
{
	mlf.mcmanager.SMCManager.popInstance(slot);

	mlf.gatekeeper.native.Caller.MLoader("app/ThemeBg.xml");
	mlf.gatekeeper.native.Caller.MLoader("app/HomePage.xml");
}

function enterUsrInfoView(param, data, slot)
{
	mlf.mcmanager.SMCManager.popInstance(slot);

	mlf.gatekeeper.native.Caller.MLoader("app/UsrInfoView.xml");
}

function enterRecordingGuide(param, data, slot)
{
	mlf.mcmanager.SMCManager.popInstance(slot);

	mlf.gatekeeper.native.Caller.MLoader("app/RecordingGuide.xml");
}

function enterRecordingSpace(param, data, slot)
{
	mlf.mcmanager.SMCManager.popInstance(slot);

	mlf.gatekeeper.native.Caller.MLoader("app/RecordingSpace.xml");
}

function enterPostProduction(param, data, slot)
{
	mlf.mcmanager.SMCManager.popInstance(slot);

	mlf.gatekeeper.native.Caller.MLoader("app/PostProduction.xml");
}

function enterReport(param, data, slot)
{
	mlf.mcmanager.SMCManager.popInstance(slot);

	mlf.gatekeeper.native.Caller.MLoader("app/Report.xml");
}

function enterReadingBrowser(param, data, slot)
{
	mlf.mcmanager.SMCManager.popInstance(slot);

	mlf.gatekeeper.native.Caller.MLoader("app/ReadingBrowser.xml");
}

function enterTaskPaper(param, data, slot)
{
	mlf.mcmanager.SMCManager.popInstance(slot);

	mlf.gatekeeper.native.Caller.MLoader("app/TaskPaper.xml");
}

function switchRecordingFlow(oldStep:Number, newStep:Number)
{
	// guide("themeCloud");
	
	mlf.mcmanager.SMCManager.popInstance(stepPortletArr[oldStep]);

	mlf.gatekeeper.native.Caller.MLoader("app/"+stepPortletArr[newStep]+".xml");

	// start Collab testing [2008/5/28]
	// while the username attribute contains string 'collab' and the new step is 'RecordingSpace', establish the collab group for all members.
	// launch the collab working flow just as mentioned by notes
	// Packages.system.Platform temp location
	if (stepPortletArr[newStep]=="RecordingSpace" && Packages.task.Composition.username.indexOf("collab")>-1)
	{
		trace("switchRecordingFlow: special");
		Packages.system.Platform.launchCollab();
	}
	// end
}

function recorder2home(currentStep:Number)
{
	mlf.mcmanager.SMCManager.popInstance(stepPortletArr[currentStep]);
	mlf.mcmanager.SMCManager.popInstance(_recorder);

	mlf.gatekeeper.native.Caller.MLoader("app/"+_home+".xml");
}

function guide(param, data, slot)
{
	trace("param: "+param);

	if (param=="dispose")
	{
		mlf.mcmanager.SMCManager.popInstance(currentGuidePortlet);
		return;
	}
	// guide page would be saved in the pageGuideIndex:Array
	// one slot to many pages
	// control the index and step
	var currentStep=Packages.components.ReadingRecorder.currentStep;

	if (param.indexOf("themeCloud")>-1)
	{
		var rgPortlet=recorderGuidePortletArr[currentStep][0];
		
		if (mlf.gatekeeper.native.Caller.scanElement(currentGuidePortlet, "guide")!=null)
		{
			mlf.mcmanager.SMCManager.popInstance(currentGuidePortlet);
		}
		else 
		{
			mlf.gatekeeper.native.Caller.MLoader("app/guide/"+rgPortlet+".xml");
			currentGuidePortlet=rgPortlet;
		}
	}
	else 
	{
		var eleArr=param.split("-");
		var stepIns=eleArr[1];
		trace("stepIns: "+stepIns);
		var nextStepIns;
		for (var i=0; i<recorderGuidePortletArr[currentStep].length; i++)
		{
			if (recorderGuidePortletArr[currentStep][i]==stepIns)
			{
				if (i<recorderGuidePortletArr[currentStep].length-1)
				{
					nextStepIns=recorderGuidePortletArr[currentStep][i+1];
				}
				else nextStepIns="lastIns";
			}
		}
		trace("nextStepIns: "+nextStepIns);
		if (nextStepIns=="lastIns")
		{
			guide("themeCloud");
		}
		else 
		{
			mlf.mcmanager.SMCManager.popInstance(currentGuidePortlet);
			mlf.gatekeeper.native.Caller.MLoader("app/guide/"+nextStepIns+".xml");
			currentGuidePortlet=nextStepIns;
		}
		var target=data.trigger;
		trace("data.trigger: "+data.trigger);
		target.onRelease();
	}
}